package com.ybt.communicate.core.endpoint;

import com.ruleengine.endpoint.IEndpoint;
import com.ruleengine.endpoint.IEndpointFactory;
import com.ruleengine.endpoint.exception.EndpointException;
import com.ybt.communicate.core.IProtocol;
import com.ybt.communicate.core.exception.ProtocolException;
import com.ybt.communicate.core.manager.ProtocolManager;

public class CommEndpointFactory implements IEndpointFactory {

    public IEndpoint createEndpoint(String target) throws EndpointException {
        // TODO Auto-generated method stub
        CommEndpoint p = new CommEndpoint();
        IProtocol s =ProtocolManager.getInstance().getProtocol(target); 
        p.setTarget(target);
        try {
            p.setConnection(s.createConnection());
            return p;
        } catch (ProtocolException e) {
           throw new EndpointException(e);
        }
    }

}
